package kr.hkit.powerjava.chapter16;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;

public class MouseHandlerEx extends JFrame /*implements MouseListener, MouseMotionListener*/ {

	private JPanel contentPane;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MouseHandlerEx frame = new MouseHandlerEx();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public MouseHandlerEx() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
//		contentPane.addMouseMotionListener(this);
//		contentPane.addMouseListener(this);
		contentPane.addMouseListener(new MouseAdapter() { //원하는 메소드만 쓰고싶을때 어댑터
			
			 //mouseAdapter 객체 생성후 필요 메소드만오버라이드
			@Override
			public void mouseClicked(MouseEvent e) {
				super.mouseClicked(e);
				display("mouseClicked", e);
			}
		});
		
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
	}
	
	
	
/*
	//마우스 리스너
	public void mouseClicked(MouseEvent e) {
		display("mouseClicked (# of clicks : " + e.getClickCount() + ")", e);
	}
	public void mouseEntered(MouseEvent e) { //컨텐트페인 영역으로 들어오면
		display("mouseEntered", e);
	}
	public void mouseExited(MouseEvent e) {
		display("mouseExited", e);
	}
	public void mousePressed(MouseEvent e) {
		display("mousePressed (# of clicks : " + e.getClickCount() + ")", e);
	}
	public void mouseReleased(MouseEvent e) {
		display("mouseReleased (# of clicks : " + e.getClickCount() + ")", e);
	}
	
	//마우스 모션
	public void mouseDragged(MouseEvent e) {
		display("mouseDragged", e);
	}
	public void mouseMoved(MouseEvent e) {
		display("mouseMoved", e);
	}
	*/
	
	public void display(String s, MouseEvent e) {
		System.out.println(s + " X=" + e.getX() + " Y=" + e.getY()); //좌표값 
	}
}
